package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.ResourceBksService;
import com.example.mybatisplus.model.domain.ResourceBks;


/**
 *
 *  前端控制器
 *
 *
 * @author zjy
 * @since 2024-07-21
 * @version v1.0
 */
@RestController
@RequestMapping("/api/resourceBks")
public class ResourceBksController {

    private final Logger logger = LoggerFactory.getLogger( ResourceBksController.class );

    @Autowired
    private ResourceBksService resourceBksService;

    /**
    * 描述：根据Id 查询
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse getById(@PathVariable("id") Long id)throws Exception {
        ResourceBks  resourceBks =  resourceBksService.getById(id);
        return JsonResponse.success(resourceBks);
    }

    /**
    * 描述：根据Id删除
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public JsonResponse deleteById(@PathVariable("id") Long id) throws Exception {
        resourceBksService.removeById(id);
        return JsonResponse.success(null);
    }


    /**
    * 描述：根据Id 更新
    *
    */
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @ResponseBody
    public JsonResponse updateResourceBks(ResourceBks  resourceBks) throws Exception {
        resourceBksService.updateById(resourceBks);
        return JsonResponse.success(null);
    }


    /**
    * 描述:创建ResourceBks
    *
    */
    @RequestMapping(value = "", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse create(ResourceBks  resourceBks) throws Exception {
        resourceBksService.save(resourceBks);
        return JsonResponse.success(null);
    }


    @GetMapping("pageList")
    public JsonResponse pageList(ResourceBks resourceBks, PageDTO dto){
        Page<ResourceBks> page = resourceBksService.pageList(resourceBks,dto);
        return JsonResponse.success(page);
    }

}

